﻿using Acme.BookStore.RoomTypes;
using Microsoft.AspNetCore.Mvc;
using SC.UserCenter.Infra;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.BookStore.ProductLabelss
{
      /// <summary>
    ///标签接口实现
    /// </summary>
    [ApiExplorerSettings(GroupName = "v2")]
    public class ProductLabelsServices : ApplicationService,IProductLabelsServices
    {
        /// <summary>
        /// 注入
        /// </summary>
        private readonly IRepository<ProductLabels> repository;

        /// <summary>
        ///构造函数
        /// </summary>
        /// <param name="repository"></param>
        public ProductLabelsServices(IRepository<ProductLabels> repository)
        {
            this.repository = repository;
        }

        /// <summary>
        ///标签显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet("GetProductLabels")]
        public async Task<ApiResult> GetProductLabels(ProductLabelsDTO dto)
        {
            var list = await repository.GetQueryableAsync();
            if(!string.IsNullOrEmpty(dto.ProductLabelsName))
            {
                list = list.Where(x => x.ProductLabelsName.Contains(dto.ProductLabelsName));
            }
            return ApiResult.Ok(list);
        }
        /// <summary>
        /// 标签添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost("PostProductLabels")]
        public async Task<ApiResult> PostProductLabels(ProductLabelsDTO dto)
        {
            var list = ObjectMapper.Map<ProductLabelsDTO, ProductLabels>(dto);
            await repository.InsertAsync(list);
            return ApiResult.Ok();
        }
        /// <summary>
        /// 标签修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut("PutProductLabels")]
        public async Task<ApiResult> PutProductLabels(ProductLabelsDTO dto)
        {
            throw new NotImplementedException();
        }
    }
}
